var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
 var theRequest = new Object();
 var id ='';
 if (url.indexOf('?') != -1) {
	 var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
	 var strs = str.split('&');
		 for (var i = 0; i < strs.length; i++) {
		    theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
		 }
		 id=theRequest.id; //此时的theRequest就是我们需要的参数；
		 console.log(id)
 }
 $(function(){
		$.ajax({
			url:'../roleController/details',
			data:{
				"id":id
			},
			success:function(data){
				console.log(data);
				pid=data.name;
				$("#nickname").val(data.nickname)
				$("#lv").val(data.tlv)
				$("#lvId").val(data.lv)
				$("#name").val(data.tname)
				$("#nameId").val(data.name)
				$("#gamearea").val(data.tnameArea)
				$("#areaCode").val(data.nameArea)
				rank()
			}
		})
	})




var gameList;
$(function(){
	$.ajax({
		url:'../nameController/getGameList',
		data:{
			"pid":0
		},
		success:function(data){
			console.log(data);
			gameList=data;
		}
	})
})
var areaList;
$(function(){
	$.ajax({
		url:'../nameController/getAreaList',
		success:function(data){
			console.log(data);
			areaList=data;
		}
	})
})
var rankList;

function rank(){
	var pid = $("#nameId").val();
	$.ajax({
		url:'../nameController/getGameList',
		data:{
			"pid":pid
		},
		success:function(data){
			console.log(data);
			rankList=data;
		}
	})
}
$("#btn").click(function(){
	var name=$("#nameId").val();
	var nickname=$("#nickname").val();
	var name_area=$("#areaCode").val();
	var lv=$("#lvId").val();
	var url='';
	if(id==""){
		url='../roleController/save'
	}else{
		url='../roleController/update'
	}
	if(name==""){
		alert("请选择游戏")
	}else if(nickname==""){
		alert("请提填写游戏昵称")
	}else if(name_area==""){
		alert("请提选择游戏大区")
	}else if(lv==""){
		alert("请提选择游戏段位")
	}else{
		$("#btn").unbind("click");
		$.ajax({
			url:url,
			data:{
				"id":id,
				"name":name,
				"nickname":nickname,
				"name_area":name_area,
				"lv":lv
			},
			success:function(data){
				alert(data)
				$("#btn").bind("click");
				window.location.href="../html/myRole.html";
			}
		})
	}
})